//
//  UIBarButtonItem.swift
//  SinaWeibo
//
//  Created by 张洪毓 on 15/11/19.
//  Copyright © 2015年 张洪毓. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //通过图片自定义barbuttonItem的便利构造函数
    convenience init(imageName: String,target: AnyObject?,actionName: String?) {
        let btn = UIButton(type: .Custom)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        if let targetObj = target,action = actionName {
            btn.addTarget(targetObj, action: Selector(action), forControlEvents: .TouchUpInside)
        }
        btn.sizeToFit()
        self.init(customView: btn)
    }
    
}
